The purpose of this script is to identify the Waterlevel and water temp, at the time of sampling each wetland
After reading in the data, we will plot it to see if the Waterlevel and water temp is within a range that “makes sense” for the environment that we are measuring.
For each wetland sampled we will take an average of the Waterlevel and water temp collected during the sample period
For example: if samples were sampled wetland 1 on 7/14/2022 between 10am and 11am, we need an average of Waterlevel and water temp from that time period
#Read in Data We will run a loop so that all water level is merged by site
#First the Hobos
setwd(here::here("Wetlands/Files_Renamed/WaterLevelDATA"))
all_files=list.files(pattern=".csv") #pulls out the csv files from CO2 folder
sites_rp = sub('_[^_]+$', '', all_files)
site_names=unique(sites_rp) #creates list of site names for following loop
#rm old files, if they exist
rm(WLData)
## Warning in rm(WLData): object 'WLData' not found
rm(Temp_WLData)
## Warning in rm(Temp_WLData): object 'Temp_WLData' not found
for (site in site_names){
list1=list.files(pattern=site) #finds all files for the site
sitelist_csv=grep(".csv",list1) #creates list of all files for site
file_list=list1[sitelist_csv]
#reads in files in list and appends
for (file in file_list){
if (!exists("WLData")){
WLData <- read.csv(file, skip=11, header = FALSE, sep = ",",
quote = "\"",dec = ".", fill = TRUE, comment.char = "")
if(str_contains(WLData[1,3],"Abs Pres, psi")){
WLData <- WLData[-1,]
colnames(WLData)=c("row","DateTime","WLPres_kpa","WLTemp_c")
WLData <- WLData[2:4]
WLData$WLPres_kpa <- as.numeric(as.character(WLData$WLPres_kpa), digits=6)
WLData$WLTemp_c <- as.numeric(as.character(WLData$WLTemp_c), digits=5)
WLData$WLPres_kpa <- WLData$WLPres_kpa*6.89476
WLData$WLTemp_c <- (WLData$WLTemp_c - 32)/1.8000
} else {
WLData <- WLData[-1,]
colnames(WLData)=c("row","DateTime","WLPres_kpa","WLTemp_c")
WLData <- WLData[2:4]
WLData$WLPres_kpa <- as.numeric(as.character(WLData$WLPres_kpa), digits=6)
WLData$WLTemp_c <- as.numeric(as.character(WLData$WLTemp_c), digits=5)
}
WLData$DateTime <- as.POSIXct(WLData$DateTime, tz="UTC",
tryFormats = c("%m/%d/%y %I:%M:%S %p",
"%m/%d/%Y %H:%M"))
}
if (exists("WLData")){
Temp_WLData <- read.csv(file, skip=1, header = FALSE, sep = ",",
quote = "\"",dec = ".", fill = TRUE, comment.char = "")
#
if(str_contains(Temp_WLData[1,3],"Abs Pres, psi")){
Temp_WLData <- Temp_WLData[-1,]
colnames(Temp_WLData)=c("row","DateTime","WLPres_kpa","WLTemp_c")
Temp_WLData <- Temp_WLData[2:4]
Temp_WLData$WLPres_kpa <- as.numeric(as.character(Temp_WLData$WLPres_kpa), digits=6)
Temp_WLData$WLTemp_c <- as.numeric(as.character(Temp_WLData$WLTemp_c), digits=5)
Temp_WLData$WLPres_kpa <- Temp_WLData$WLPres_kpa*6.89476
Temp_WLData$WLTemp_c <- (Temp_WLData$WLTemp_c - 32)/1.8000
} else {
Temp_WLData <- Temp_WLData[-1,]
colnames(Temp_WLData)=c("row","DateTime","WLPres_kpa","WLTemp_c")
Temp_WLData <- Temp_WLData[2:4]
Temp_WLData$WLPres_kpa <- as.numeric(as.character(Temp_WLData$WLPres_kpa), digits=6)
Temp_WLData$WLTemp_c <- as.numeric(as.character(Temp_WLData$WLTemp_c), digits=5)
}
Temp_WLData$DateTime <- as.POSIXct(Temp_WLData$DateTime, tz="UTC",
tryFormats = c("%m/%d/%y %I:%M:%S %p",
"%m/%d/%Y %H:%M"))
WLData <- rbind(WLData, Temp_WLData)
rm(Temp_WLData)
}
}
WLData$DateTime <- round_date(WLData$DateTime, "15 mins")
WLData$Station <- site
WLData=unique(WLData)
assign((paste(site,sep="_")),WLData) #creates object with new appended data
rm(WLData) #removes WLdata so that multiple sites aren't appended together
}
#Clean Data
## Warning: Removed 2 rows containing missing values (geom_point).
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plotly.com/r/reference/#scatter
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## Warning: Ignoring 2 observations
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plotly.com/r/reference/#scatter
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## Warning: Ignoring 1 observations
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plotly.com/r/reference/#scatter
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## Warning: Ignoring 1 observations
plot all water level data
## Warning: Removed 22 rows containing missing values (geom_point).
## Warning: Removed 22 rows containing missing values (geom_point).
##select data select the wetland you want to find water level and water temp from and the date and time
plot the water level and water temp for the entire day
#start here amy!!
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plotly.com/r/reference/#scatter
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plotly.com/r/reference/#scatter
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## WaterlLevel_mean WaterTemp_mean
## 1 69.0972 5.3676